package la.bbs558.controller.user;

import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import la.bbs558.aop.valid.Check;
import la.bbs558.aop.valid.Valid;
import la.bbs558.controller.base.BaseController;
import la.bbs558.controller.base.Result;
import la.bbs558.entity.AppDownload;
import la.bbs558.entity.BbsPost;
import la.bbs558.entity.params.BbsPostPage;
import la.bbs558.service.AppDownloadService;
import la.bbs558.service.BbsPostService;
import la.bbs558.service.StatisticsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Objects;

/**
 * @Classname IndexController
 * @Description 首页
 * @Date 2023/12/15 10:27
 * @Created by weihanmin
 */
@RestController
@RequestMapping("index")
@Check
public class IndexController extends BaseController {

    @Resource
    private StatisticsService statisticsService;

    @Resource
    private BbsPostService bbsPostService;

    @Resource
    private AppDownloadService appDownloadService;

    @GetMapping("statistics")
    @SaIgnore
    public Result<?> statistics() {
        return Result.success(statisticsService.statistics());
    }

    @GetMapping("post")
    @SaIgnore
    public Result<?> post() {
        return Result.success(statisticsService.post());
    }

    @GetMapping("section")
    @SaIgnore
    public Result<?> section() {
        return Result.success(statisticsService.section());
    }

    @GetMapping("collect")
    @SaIgnore
    public Result<?> collect() {
        return Result.success(statisticsService.collectBoardList());
    }

    @GetMapping("appDownload")
    @SaIgnore
    public Result<?> appDownload() {
        AppDownload appDownload = appDownloadService.lambdaQuery()
                .eq(AppDownload::getStatus, 1)
                .last("limit 1").one();
        return Result.success(Objects.isNull(appDownload) ? "" : appDownload.getUrl());
    }

    @GetMapping("appPost")
    @SaIgnore
    public Result<?> highlightPost(Page<BbsPost> page, @Valid(msg = "参数不能为空") Long classId) {
        BbsPostPage bbsPostPage = new BbsPostPage();
        bbsPostPage.setCurrent(page.getCurrent());
        bbsPostPage.setSize(page.getSize());
        bbsPostPage.setDesc("desc");
        bbsPostPage.setClassId(classId);
        bbsPostService.postList(bbsPostPage);
        return Result.success(bbsPostPage);
    }

    @GetMapping("registerShowInfo")
    @SaIgnore
    public Result<?> registerShowInfo() {
        return Result.success(Arrays.asList(
                "喜迎龙年",
                "为了庆祝新春佳节，现阶段为开放性注册",
                "邀请码:518194"
        ));
    }

}
